package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.DataTypeUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActCdSets;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQuery;

import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.*;

@Entity
@NamedQuery(name = "WorkingList.findAll", query = "select o from WorkingList o")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("LIST")
public class WorkingList extends Act implements Serializable {
    
//    public CE OwnershipLevelCode;
    
    public WorkingList() throws Hl7Exception {
    }
    
    public void setOwnershipLevelCode(CE ce) {
    	if(null != ce && ce.codeSystemEnName()!=null && ce.codeName()!= null)
        {
            this.setRimCoreActCdSets(ce, WLOWNERSHIPLEVELCDSETCODE);
        }
        else
        {
            this.setWlOwnershipLevelCodeEtsId(ce.code().toString());
        }
    }

    public CE getOwnershipLevelCode() throws Hl7Exception {
    	if (this.getWlOwnershipLevelCodeEtsId().equals(WLOWNERSHIPLEVELCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getWlOwnershipLevelCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }            
        }
        else
            return DataTypeUtil.getCE(this.getWlOwnershipLevelCodeEtsId()); 
        return null;
    }
    
//WorkingList    
    @Column(name = "WL_OWNERSHIP_LEVEL_CODE_ETS_ID")    
    protected String wlOwnershipLevelCodeEtsId = WLOWNERSHIPLEVELCDSETCODE.toString();
    
    protected String getWlOwnershipLevelCodeEtsId() {
        return wlOwnershipLevelCodeEtsId;
    }

    protected void setWlOwnershipLevelCodeEtsId(String wlOwnershipLevelCodeEtsId) {
        this.wlOwnershipLevelCodeEtsId = wlOwnershipLevelCodeEtsId;
    }

}
